import { Layers, Node, UITransform } from "cc"
import { EntityTypeEnum } from "../Common"
import { IconBaseColorEnum, IconLightColorEnum, LightColorEnum, PanelColorEnum } from "../Enum"

export const createUINode = (name?: string | EntityTypeEnum) => {

    if (typeof (name) === 'number') {
        name = EntityTypeEnum[name]
    }

    const node = new Node(name || '')
    node.addComponent(UITransform)
    node.layer = 1 << Layers.nameToLayer('UI_2D')

    return node
}

/** 字符串截取，默认5位 */
export const toFixedString = (str: string, length = 8) => {
    return str.substring(0, length)
}

/** 获取面板边框颜色 */
export const getPanelFrameColor = (star: number) => {
    switch (star) {
        case 1:
            return LightColorEnum.normal
        case 2:
            return LightColorEnum.green
        case 3:
            return LightColorEnum.blue
        case 4:
            return LightColorEnum.purple
        case 5:
            return LightColorEnum.orange
        case 6:
            return LightColorEnum.red
        default:
            return LightColorEnum.normal
    }

}

/** 获取icon边框颜色 */
export const getIconFrameColor = (star: number) => {
    switch (star) {
        case 1:
            return IconLightColorEnum.normal
        case 2:
            return IconLightColorEnum.green
        case 3:
            return IconLightColorEnum.blue
        case 4:
            return IconLightColorEnum.purple
        case 5:
            return IconLightColorEnum.orange
        case 6:
            return IconLightColorEnum.red
        default:
            return IconLightColorEnum.normal
    }

}

/** 获取面板底色 */
export const getPanelBaseColor = (star: number) => {
    switch (star) {
        case 1:
            return PanelColorEnum.normal
        case 2:
            return PanelColorEnum.green
        case 3:
            return PanelColorEnum.blue
        case 4:
            return PanelColorEnum.purple
        case 5:
            return PanelColorEnum.orange
        case 6:
            return PanelColorEnum.red
        default:
            return PanelColorEnum.normal
    }

}

/** 获取icon底色 */
export const getIconBaseColor = (star: number) => {
    switch (star) {
        case 1:
            return IconBaseColorEnum.normal
        case 2:
            return IconBaseColorEnum.green
        case 3:
            return IconBaseColorEnum.blue
        case 4:
            return IconBaseColorEnum.purple
        case 5:
            return IconBaseColorEnum.orange
        case 6:
            return IconBaseColorEnum.red
        default:
            return IconBaseColorEnum.normal
    }

}
/** 秒转换为时间 */
export const convertSecondsToTime = (seconds: number): string => {
    const minutes = Math.floor(seconds / 60);
    const remainingSeconds = Math.floor(seconds % 60);
    const formattedMinutes = minutes < 10 ? `0${minutes}` : `${minutes}`;
    const formattedSeconds = remainingSeconds < 10 ? `0${remainingSeconds}` : `${remainingSeconds}`;
    return `${formattedMinutes}:${formattedSeconds}`;
}
